<?php


class Sitemap_IndexController extends WSB_Xtension_Navigation
{
	protected $_noViewRenderer = true;

	private $_html;

	public function indexAction()
	{
		$node = WSB_Node_Page::getTree();
		$this->_walkThroughPageNode($node);
		$this->addContent($this->wrapInBaseClass($this->_html));
	}

	private function _walkThroughPageNode(WSB_Node_Page $node)
	{
		if($node->hasVisibleChildren()) {
			$this->_html .= '<ul>';
			foreach($node->getChildren() AS $child) {
				if($child->isVisible()) {
					$this->_html .= '<li>';
					$this->_html .= sprintf('<a href="%s">%s</a>', $this->_getHref($child->getPageId()), $child->title);
					if($child->hasVisibleChildren()) {
						$this->_walkThroughPageNode($child);
					}
					$this->_html .= '</li>';
				}
			}
			$this->_html .= '</ul>';
		}
	}

	private function _getHref($id)
	{
		$url = WSB_Xtension_Url::getInstance();
		return $url->getHrefToPage($id);
	}

}
